layui.use(['form','jquery','jquery_cookie'], function () {
    var form = layui.form,
        layer = layui.layer,
        $ = layui.jquery,
        $ = layui.jquery_cookie($);


    form.on('submit(btn_updatePwd)',function (data) {
        data =data.field;
        //原密码
       var userPwd = data.userPwd;
        //新密码
       var newPwd = data.newPwd;
        //重复密码
       var repeatPwd =data.repeatPwd;

       //判断原始密码是否与新密码一致
        if(userPwd==newPwd){
            layer.msg("新密码不能与原密码相同")
            return;
        }
        if(newPwd != repeatPwd){
            layer.msg("重复密码不一致")
            return;
        }


        $.ajax({
            type:"put",
            url:ctx+"/user",
            data:{
                userPwd:userPwd,
                newPwd:newPwd,
                repeatPwd:repeatPwd
            },
            dataType:"json",
            success:function (data) {
                if(data.code==200){
                    layer.msg("密码修改成功,系统将在3秒后自动退出...",function () {
                        $.removeCookie("userIdStr",{path:"/"});
                        $.removeCookie("userName",{path:"/"});
                        $.removeCookie("trueName",{path:"/"});
                        setTimeout(function () {
                            // 修改密码成功后，跳转到登陆(父窗口 毕竟这是ifram)
                            window.parent.location.href=ctx+"/index";
                        },3000);
                    })
                }else{
                    layer.msg(data.msg);
                }
            }
        })

    })
    



});